<?php
/**
 * CreateTime: 2024/1/5 16:26
 * User:LinQ
 */

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class cModuleMiddleware
{
    public function handle(Request $request, Closure $next): Response
    {
        $config = config('modules');
        $className = $request->route()->getControllerClass();
        // 获取最后一个反斜杠的位置
        $lastSlashPosition = strrpos($className, '\\');
        // 截取出 Controller 前面的一层
        $namespace = substr($className, 0, $lastSlashPosition);
        if(isset($config[$namespace])&&$config[$namespace]==false){
            die("modules err");
        }
        return $next($request);
    }

}
